CreateObjcInformalDelegateWithContext
Type
handler
Summary
Create an Objective-C object with LCB implementations of methods of an informal protocol.
Syntax
CreateObjcInformalDelegateWithContext(<pProtocol>,<pHandlerMapping>,<pContext>)
Description
Use the CreateObjcInformalDelegateWithContext handler to create instances of Objective-C delegate classes with LCB implementations of protocol methods, when the Protocol object cannot be found at runtime. This occurs for example when all of the protocol methods are optional.
Instead of a protocol name (as with CreateObjcDelegateWithContext), the pProtocol argument of CreateObjcInformalDelegateWithContext must be a proper list of foreign handlers for each of the methods of the protocol for which LCB callbacks are provided in the pHandlerMapping array.
Once created an informal delegate can be set in the usual way on an
instance of the appropriate class (by binding to -setDelegate:
),
typically so that callbacks triggered by user interaction with a widget
can be handled in LCB.
If no context is required to be passed as a parameter to the callback, use CreateObjcInformalDelegate.
If the protocol can be resolved at runtime, it is generally easier to use the CreateObjcDelegateWithContext handler.
Parameters
Name | Type | Description |
---|---|---|
pProtocol | A list of foreign handlers which bind to protocol methods | |
pHandlerMapping | A mapping from the protocol's selector names to LCB handlers |
Examples
foreign handler Objc_NSPortMessageGetMsgId(in pMessage as ObjcId) returns UInt32 \
binds to "objc:NSPort.-msgid"
handler HandlePortMessageCallback(in pPortIndex as Integer, in pMessage as ObjcId) returns nothing
post "portMessage" with [mPortList[pPortIndex]["name"], \
Objc_NSPortMessageGetMsgId(pMessage)]
end handler
foreign handler Objc_NSPortDelegateHandlePortMessage(in pTarget as ObjcId, in pPortMessage as ObjcId) returns nothing \
binds to "objc:.-handlePortMessage:"
public handler GetNSPortDelegate(in pPortIndex as Integer)
return CreateObjcInformalDelegateWithContext([Objc_NSPortDelegateHandlePortMessage], \
{ "handlePortMessage:": \
HandlePortMessageCalback }, \
pPortIndex)
end handler
Related
handler: CreateObjcDelegate, CreateObjcDelegateWithContext, CreateObjcInformalDelegate